package com.gitee.zycra.future.job.common.enums;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zycra
 */
public enum JobCycleEnum implements CommonEnum<JobCycleEnum> {

    /**
     * 执行周期
     */
    YEAR(1, "年", 525600),
    MONTH(2, "月", 43800),
    WEEK(3, "周", 10080),
    DAY(4, "日", 1440),
    HOUR(5, "时", 60),
    MINUTE(6, "分", 1);

    /**
     * 枚举值
     */
    private final Integer code;

    /**
     * 枚举描述
     */
    private final String desc;

    /**
     * 分钟数
     */
    private final int minutes;

    private static final Map<Integer, JobCycleEnum> MAP = new HashMap<>();

    private static final Map<Integer, String> DIRECT_MAP = new LinkedHashMap<>();

    static {
        for (JobCycleEnum value : JobCycleEnum.values()) {
            MAP.put(value.getCode(), value);
            DIRECT_MAP.put(value.getCode(), value.getDesc());
        }
    }

    JobCycleEnum(Integer code, String desc, int minutes) {
        this.code = code;
        this.desc = desc;
        this.minutes = minutes;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public int getMinutes() {
        return minutes;
    }

    public static JobCycleEnum getByCode(Integer code) {
        return MAP.get(code);
    }

    public static Map<Integer, String> getMap() {
        return DIRECT_MAP;
    }
}
